<template>
  <div class="mnt-dialog form-container">
    <el-form ref="form" :model="formModel" label-width="100px" :rules="rules">
      <el-row style="text-align: center">
        <el-col :span="24" v-if="showDesc">
          <el-form-item label="冻结理由:" prop="holdReasonDesc">
            <el-input type="textarea" v-model="formModel.holdReasonDesc" />
          </el-form-item>
        </el-col>
        <el-col :span="24" v-if="!showDesc">
          <el-form-item label="删除理由:" prop="deleteReasonDesc">
            <el-input type="textarea" v-model="formModel.deleteReasonDesc" />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <el-row class="submit-area">
      <el-col :span="24">
        <el-button @click="closeDialog">取消</el-button>
        <el-button type="primary" @click="handleSubmit()">确定</el-button>
      </el-col>
    </el-row>
  </div>
</template>

<script>

export default {
  name: 'ProductPlanHoldAndDel',
  components: {

  },
  props: ['pageType', 'editData'],
  data() {
    return {
      operateTypeOptions:[{operateType:'11',operateTypeDesc:'冻结'},{operateType:'03',operateTypeDesc:'删除'}],
      showDesc:true,
      formModel: {
        rcrdId: '',
        planNo: '',
        holdReasonDesc: '',
        deleteReasonDesc: '',
      },
      rules: {
      }
    }
  },
  computed: {

  },
  mounted() {
    this.init()
  },
  methods: {
    init() {
      this.$form = this.$refs.form
      const {pageType, editData, formModel} = this
      if(pageType=='hold'){
        this.showDesc = true
        this.formModel.deleteReasonDesc = ''
      }else if(pageType=='del'){
        this.showDesc = false
        this.formModel.holdReasonDesc = ''
      }
      this.assignData(editData, formModel)
      this.initRules()
    },
    initRules() {
      const REQUIRED_MSG = this.CONST.REQUIRED_MSG
      this.rules = {
        holdReasonDesc: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
        deleteReasonDesc: [{ required: true, message: REQUIRED_MSG, trigger: ['change', 'blur'] }],
      }
      this.$nextTick(_ => {
        this.$form.clearValidate()
      })
    },
    handleSubmit() {
      this.$refs.form.validate(valid => {
        if (valid) {
          const { pageType, formModel } = this
          const param = { ...formModel }
          const url = '/teOfmVehiclePlan/maintainTeOfmVehiclePlan'
          const operateType = pageType === 'hold' ? '11' : '03'
          param.operateType = operateType
          const tip = '操作成功!'
          this.post(url, param).then(res => {
            this.$info(tip, () => {
              this.$emit('mntSuc', res)
              this.closeDialog()
            })
          })
        }
      })
    },
    closeDialog() {
      this.$parent.$emit('update:visible', false)
    },
  }
}
</script>

<style lang="scss" scoped>

</style>
